package com.ylbh.modules.businesscoupon.controller;

import java.util.Arrays;
import java.util.Map;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.businesscoupon.dto.StoreCouponDTO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.businesscoupon.entity.ShoppingStoreCoupon;
import com.ylbh.modules.businesscoupon.service.ShoppingStoreCouponService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.R;



/**
 *
 * 商家优惠券
 * @author czx
 * @date 2019-11-05 14:27:27
 */
@RestController
@RequestMapping("business/coupon")
public class ShoppingStoreCouponController {
    @Autowired
    private ShoppingStoreCouponService shoppingStoreCouponService;

    @ApiOperation("商家优惠券列表")
    @GetMapping("/queryStoreCouponList")
    @RequiresPermissions("business:coupon:list")
    public CommonResult queryStoreCouponList(StoreCouponDTO storeCouponDTO) {
        PageUtils page = shoppingStoreCouponService.queryStoreCouponList(storeCouponDTO);
        return Ref.ok(page);
    }

    @ApiOperation("查看商家优惠券详情")
    @GetMapping("/getStoreCouponInfoById/{id}")
    @RequiresPermissions("business:coupon:info")
    public CommonResult getStoreCouponInfoById(@PathVariable("id") String id) {
		ShoppingStoreCoupon shoppingStoreCoupon = shoppingStoreCouponService.getStoreCouponInfoById(id);
        return Ref.ok(shoppingStoreCoupon);
    }

    @SysLog("优惠券审核操作")
    @ApiOperation("优惠券审核操作")
    @PostMapping("toExamineCouponById")
    @RequiresPermissions("business:coupon:toExamineCouponById")
    public CommonResult toExamineCouponById(@RequestBody ShoppingStoreCoupon shoppingStoreCoupon) {
        shoppingStoreCouponService.toExamineCouponById(shoppingStoreCoupon);
        return Ref.ok(shoppingStoreCoupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:coupon:save")
    public CommonResult save(@RequestBody ShoppingStoreCoupon shoppingStoreCoupon){
		shoppingStoreCouponService.save(shoppingStoreCoupon);

        return Ref.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:coupon:update")
    public CommonResult update(@RequestBody ShoppingStoreCoupon shoppingStoreCoupon){
		shoppingStoreCouponService.updateById(shoppingStoreCoupon);

        return Ref.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:coupon:delete")
    public CommonResult delete(@RequestBody String[] ids){
		shoppingStoreCouponService.removeByIds(Arrays.asList(ids));
        return Ref.ok();
    }

}
